package com.qfedu.controller;


import com.github.pagehelper.Page;
import com.qfedu.common.JsonResult;
import com.qfedu.entity.Vip;
import com.qfedu.service.VipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/vip")
public class VipController {
    @Autowired
    private VipService vipService;

    /**
     * 添加Vip信息
     * @param content 申请理由内容
     * @return
     */
    @RequestMapping("add.do")
    @ResponseBody
    public JsonResult add(String content) {

        vipService.add(content);
        return new JsonResult(1,"添加成功！");
    }

    /**
     * 查询当前所有VIP申请
     * @param page 前端获取的页数
     * @param limit 前端获取的页容量
     * @return
     */
    @RequestMapping("queryVip.do")
    @ResponseBody
    public Map<String, Object> queryVip(Integer page, Integer limit) {
        List<Vip> list = vipService.select(page, limit);

        // 获取总记录数
        long total = ((Page) list).getTotal();

        HashMap<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", total);
        map.put("data", list);
        System.out.println(map);
        return map;
    }

}
